package com.example.pageexample.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

/**
 * 创建本地room数据库
 * @author mailanglideguozhe
 * @date 20210623
 */
@Database(entities = {Picture.class},version = 1,exportSchema = false)
public abstract class BaseDatabase extends RoomDatabase {
    private static String DB_NAME = "base.db";
    private static BaseDatabase sDatabase;
    public abstract PictureDao pictureDao();

    public static synchronized BaseDatabase getInstance(Context context){
        if(null == sDatabase){
            sDatabase = create(context);
        }
        return sDatabase;
    }

    private static BaseDatabase create(final Context context){
        return Room.databaseBuilder(context , BaseDatabase.class , DB_NAME).build();
    }
}
